<?php
require_once 'includes/haut.php';
acces($niveau,1);

require_once 'modules/gestionCreation.php';
require_once 'includes/donneesFormulaires.php';

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Nouvelle cr&eacute;ation</title>
		<?php include('includes/headLinks.php');?>
		<script type="text/javascript" src="js/ajoutCreation.js"></script>
	</head>
	<body>
		<div id="entete">
		</div>

		<div id="navigation">
			<?php include('includes/navigation.php'); ?>
		</div>

		<div id="principal">
			<?php
			function select_list($from, $to, $val){
				for($x=$from; $x<=$to; $x++){
					if ($x==$val && $val!=null){
						echo'<option value="'.$x.'" selected="selected">'.$x.'</option>';
					}else {
						echo'<option value="'.$x.'">'.$x.'</option>';
					}
				}
			}

			if(isset($_GET["action"]) && $_GET["action"]=="modifier"){
				echo '<h2>Modifier ma cr&eacute;ation</h2>';
			}else{
				echo '<h2>Ajouter une nouvelle cr&eacute;ation</h2>';
			} ?>

			<form action="ajoutCreation.php" method="post">

				<div class="error">
					* Champs obligatoires</br>
					<?php
					if(isset($creation))
						echo $erreursCreation;
					else if (isset($_GET["idCreation"])) {
						$idCreation = $_GET["idCreation"];
						$res = creation::getCreationById($idCreation);
						if ($res!=null){
							$creation = new creation($res['modele'], $res['categorie1'],$res['categorie2'],$res['taille'],$res['description'],$res['dispo'],$res['prix']);
						} else {
							$creation = new creation();
						}
					}else
						$creation = new creation();
					?>
				</div>
				
				<table>
					<tr>
						<th><label for="modele">Nom du mod&egrave;le * : </label></th>
						<td><input type="text" name="modele" id="modele"  value="<?php echo $creation->getModele();?>" maxlength="100"/></td>
					</tr>
					<tr>						
						<th><label for="cat1">Cat&eacute;gorie * : </label></th>
						<td><select name="cat1" id="cat1">
								<option value="" >S&eacute;lectionnez une cat&eacute;gorie</option>
								<?php preSelect($tabCat1, $creation->getCategorie1());?>
							</select>
						</td>
					</tr>
					<tr>
						<th><label for="cat2">Sous-cat&eacute;gorie * : </label></th>
<!-- 						a remplir par js selon cat1 : select ou radio -->
						<td><select name="cat2" id="cat2" data-val="<?php echo $creation->getCategorie2();?>">
								<option value="">S&eacute;lectionnez une sous-cat&eacute;gorie</option>
								<?php if ($creation->getCategorie1()!=null) preSelect($tabCat1Cat2[$creation->getCategorie1()], $creation->getCategorie2());?>
							</select>
						</td>
					</tr>
					<tr>
						<th><label for="taille">Taille : </label></th>
						<td><input type="text" name="taille" id="taille" value="<?php echo $creation->getTaille();?>" maxlength="20"/></td>
					</tr>
					<tr>
						<th><label for="description">Description : </label></th>
						<td><textarea name="description" id="description"><?php echo $creation->getDescription();?></textarea></td>
					</tr>
					<tr>
						<th><label for="dispo">Nombre * : </label></th>
						<td><select name="dispo" id="dispo">
						<option value="">S&eacute;lectionnez le nombre de mod&egrave;les disponibles</option>
                                <?php select_list(0, 30, $creation->getDispo()); ?>
                            </select>
						</td>
					</tr>
					<tr>
						<th><label for="prix">Prix * : </label></th>
						<td><input type="text" name="prix" id="prix" value="<?php echo $creation->getPrix();?>" maxlength="20"/></td>
					</tr>
				</table>

				<p>
					<center> <input class="submit" type="submit" name="envoyer" value="Envoyer" />
					&nbsp;&nbsp;&nbsp;&nbsp; <input class="submit" type="reset" name="reset"
						value="R&eacute;initialiser" /> </center>
				</p>
				<p>
				<?php
				if(isset($_GET["action"]) && $_GET["action"]=="modifier"){
					echo '<input type="hidden" name="idCreation" value="'.$idCreation.'" />
						<input type="hidden" name="action" value="modifier" />';
				}else{
					echo '<input type="hidden" name="action" value="ajouter" />';
				} ?>
					
				</p>
			</form>
		</div>

		<div id="form_connexion">
			<?php include('includes/formConnexion.php'); ?>
		</div>
	</body>
</html>